<?php
/* Description: This file is used to add sub category */
#########IncludeFiles####################################################################################
include_once '../inc/config.php';
include_once("../inc/bootstrape.php");
require_once _SITE_PATH_.'classes/Vendor/Vendor.php';
require_once _SITE_PATH_.'classes/Category/Category.php';
require_once _SITE_PATH_.'classes/CommonUtility/CommonUtility.php';

$category_id = isset($_REQUEST['category_id'])?$_REQUEST['category_id']:'';
$id = trim($_REQUEST['id']); 
if( $_POST['submit']=='Submit'){    
    $parms['name'] = $_POST['name'];
	$parms['id'] = $_POST['id'];
	$category_id = $_POST['category_id'];
	$parms['parent_id'] = $_POST['parent_id'];
	$parms['depth'] = 1;
	$parms['added'] = date("Y-m-d h:i:s");
	$parms['modified'] = date("Y-m-d h:i:s");
	
	$condition = array(); 
	$condition['id'] = $parms['id'];
	if( CommonUtility::updateData($parms, 'category', $condition)) {  
        header("Location: subcategory_mng.php?category_id=".$category_id."&msg=1093");            
        exit;
    }
    $err = 1094;    
}

$main_categories = array();
$main_categories = Category::getMainCategories();

$sub_categories = Category::getSubCategories($id,'id');
$result = $sub_categories[0];

$errMsg = $err;
$_tplName = 'category/subcategory_edit.tpl';
$_title = 'Edit Sub-Category';
require_once _ADMIN_TPL_MAIN_;
?>